<template>
	<view class="content">
		<!-- 顶部 -->
		<view class="header">
			<view class="">
				<image src="../../static/img/T/12.png" mode=""></image>
				{{data.title}}
				<image src="../../static/img/T/12s.png" mode=""></image>
			</view>
		</view>
		<!-- 导航栏 -->
		<swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" indicator-active-color='rgba(254, 254, 254, 1)'>
			<swiper-item v-for="(item,index) in AdvList" :key='index'>
				<image :src="item.adv_image" mode="scaleToFill" lazy-load></image>
			</swiper-item>
		</swiper>
		<!-- 导航 -->
		<view class="nav">
			<view class="li" v-for="(item,index) in GoodsCategory" :key='index' @tap="select_nav(item.category_id,index)" :class="index==current?'active':''">
				{{item.category_name}}
				<view class="row" v-if="index==current">

				</view>
			</view>
		</view>
		<!-- T恤 -->
		<view class="Shirt">
			<view class="li" v-for="(item,index) in GoodsList" :key='index'>
				<image :src="item.pic_cover" mode="aspectFit" @tap='select_T(item.goods_id)'></image>
				<view class="text">
					{{item.goods_name}}
				</view>
			</view>
		</view>
		<!-- <view class="bot">
			<view class="left">
				<image src="../../static/tab/indexs.png" mode=""></image>
			    <view class="title active">
			    	首页
			    </view>
			</view>
			<view class="left"  @tap='index'>
				<image src="../../static/tab/users.png" mode=""></image>
			    <view class="title">
			    	我的
			    </view>
			</view>
		</view> -->

		<!-- 弹框 -->
		<uni-popup ref="popup_coupon" type="center">
			<view class="new">
				<image src="../../static/img/15.png" mode="scaleToFill" @tap='receive'></image>
			</view>
		</uni-popup>
		<!-- 加载 -->
		<uni-load-more showIcon iconType='iconType' status='loading' v-if="GoodsList.length==0"></uni-load-more>
	</view>
</template>

<script>
	import '../../static/js/jquery.js'
	import uniPopup from '@/components/uni-popup/uni-popup.vue'
	import uniPopupMessage from '@/components/uni-popup/uni-popup-message.vue'
	import uniPopupDialog from '@/components/uni-popup/uni-popup-dialog.vue'
	import uniLoadMore from "@/components/uni-load-more/uni-load-more.vue"
	export default {
		data() {
			return {
				current: 0,
				GoodsCategory: [],
				GoodsList: [],
				value: '',
				code: null,
				CouponList: [],
				data: {},
				userInfo: {},
				AdvList: [],
				uid: null,
				Page: 1,
				redirect: '',
				sdaty: false,
				wxcode: false,
			}
		},
		onReady() {


			var hot = window.location.href;
			hot = hot.split('code')[1];

			var _wxcode = uni.getStorageSync('wxcode');
			//console.log(_wxcode)
			if (hot == undefined && _wxcode == '' || _wxcode == '' || hot == undefined) {
				//alert
				uni.showModal({
					showCancel: false,
					content: '授权登录',
					confirmText: '去登陆',
					success: (res) => {
						if (res.confirm) {
							this.sdaty = true;
							//window.location.replace('https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxb36e4c3935f4f061&redirect_uri=http%3A%2F%2Fjwdz.shenghuang365.com%2Fmobile%2Fh5&response_type=code&scope=snsapi_userinfo&state=123&connect_redirect=1#wechat_redirect')
							//window.location.replace('https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxb36e4c3935f4f061&redirect_uri=https%3A%2F%2Fwww.jiwu.art&response_type=code&scope=snsapi_userinfo&state=123#wechat_redirect')
							window.location.replace(
								'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxb36e4c3935f4f061&redirect_uri=https%3A%2F%2Fwww.jiwu.art%2Fp&response_type=code&scope=snsapi_userinfo&state=123#wechat_redirect'
							)
							uni.setStorageSync('wxcode', 'true')
						};
					}
				});
				return false;
			};

			//alert(_wxcode)
			//hot = hot[1];
			hot = hot.split('&');
			hot = hot[0];
			var code = hot.substr(1, hot.length);
			this.code = code;
			//alert(this.code)

			var _this = this;
			//console.log(code);
			_this.infoprop('/Common/Login', 'GET', {
				code: _this.code
			}, (res1) => {
				//alert(JSON.stringify(res1))

				if (res1.data.status == 0) {
					uni.showModal({
						showCancel: false,
						content: '授权登录',
						confirmText: '去登陆',
						success: (res) => {
							if (res.confirm) {
								this.sdaty = true;
								//window.location.replace('https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxb36e4c3935f4f061&redirect_uri=http%3A%2F%2Fjwdz.shenghuang365.com%2Fmobile%2Fh5&response_type=code&scope=snsapi_userinfo&state=123&connect_redirect=1#wechat_redirect')
								//window.location.replace('https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxb36e4c3935f4f061&redirect_uri=https%3A%2F%2Fwww.jiwu.art&response_type=code&scope=snsapi_userinfo&state=123#wechat_redirect')
								window.location.replace(
									'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxb36e4c3935f4f061&redirect_uri=https%3A%2F%2Fwww.jiwu.art%2Fp&response_type=code&scope=snsapi_userinfo&state=123#wechat_redirect'
								)
								uni.setStorageSync('wxcode', 'true')
							};
						}
					});

					return false;
				};
				uni.setStorageSync('uid', res1.data.data.uid);
				_this.uid = res1.data.data.uid;
				//alert(res1.data.data.uid)
				_this.infoprop('/Index/index', 'POST', {
					Uid: res1.data.data.uid,
					Page: _this.Page,

				}, (res) => {
					//alert(JSON.stringify(res))
					_this.AdvList = res.data.data.AdvList
					_this.GoodsCategory = res.data.data.GoodsCategory;
					_this.GoodsList = res.data.data.GoodsList;
					_this.data = res.data.data;
					console.log(_this.AdvLisst);
					if (res.data.data.IsHaveRecievedCoupon == 0) {
						_this.CouponList = res.data.data.CouponList;
						console.log(_this.CouponList)
						_this.open()
					}
				});

			});


		},
		onReachBottom() {
			this.Page += 1;
			this.getData({
				Uid: this.uid,
				Page: this.Page,
				CatId: this.car_id
			});
			//console.log(this.Page);

		},
		onLoad(e) {
			window.sessionStorage.setItem('firstEntryUrl', window.location.href)
		},
		methods: {
			index() {
				uni.navigateTo({
					url: '../our/our'
				});
			},
			open() {
				this.$refs.popup_coupon.open();
			},
			logn() { //登录授权

			},

			select_nav(id, index) {
				this.current = index;
				this.car_id = id;
				this.GoodsList = [];
				this.Page = 1;
				this.getData({
					Uid: this.uid,
					Page: this.Page,
					CatId: this.car_id
				});
			},
			select_T(id) {
				console.log(id)
				uni.navigateTo({
					url: '../T_info/T_info?id=' + id
				})
			},
			receive() { //领取优惠卷
				var coupon_id = "";
				for (var i = 0; i < this.CouponList.length; i++) {
					//coupon_id.push(this.CouponList[i].coupon_type_id);
					coupon_id += this.CouponList[i].coupon_type_id;
				}
				this.infoprop('/Coupon/RecieveCoupon', 'POST', {
					Uid: this.uid,
					CouponTypeId: coupon_id,
				}, (res) => {
					if (res.data.status == 1) {
						uni.showToast({
							title: '领取成功!',
							icon: 'none',
							success: () => {
								this.$refs.popup_coupon.close();
							}
						});

					} else {
						uni.showToast({
							title: res.data.msg,
							icon: 'none',
							success: () => {
								this.$refs.popup_coupon.close();
							}
						});
					}
					//console.log(res)
				});
			},
			getData(data) {
				this.infoprop('/Index/index', 'POST', data, (res) => {
					this.GoodsCategory = res.data.data.GoodsCategory;
					this.AdvList = res.data.data.AdvList
					this.GoodsList = [...this.GoodsList, ...res.data.data.GoodsList];
					if (res.data.data.IsHaveRecievedCoupon == 0) {
						this.CouponList = res.data.data.CouponList;
						console.log(this.CouponList)
						this.open()
					}
				});
			}
		},
		components: {
			uniPopup,
			uniLoadMore
		}
	}
</script>

<style lang="scss" scoped>
	page {
		background-color: #EEEEEE;
	}

	.content {
		background-color: #FFFFFF;

		swiper {
			height: 300rpx;
			position: relative;

			image {
				width: 100%;
				height: 100%;
			}
		}

		.log {
			width: 500rpx;
			height: 300rpx;
			background-color: #FFFFFF;

			.text {
				text-align: center;
				font-size: 30rpx;
				padding-top: 100rpx;
			}

			button {
				font-size: 30rpx;
				width: 300rpx;
				height: 60rpx;
				line-height: 60rpx;
				margin-top: 20rpx;
			}
		}

		//弹框
		.new {
			width: 650rpx;
			height: 800rpx;
			background: url(../../static/img/11.png) no-repeat;
			background-size: 100% 100%;
			display: flex;
			justify-content: center;
			align-items: center;

			image {
				width: 500rpx;
				height: 100rpx;
				margin-top: 650rpx;
			}
		}

		//顶部
		.header {
			//padding: 50rpx 0;
			font-size: 40rpx;
			font-family: PingFang SC;
			font-weight: bold;
			color: rgba(255, 255, 255, 1);
			display: flex;
			justify-content: center;
			border-bottom: 1rpx solid #EEEEEE;
			background-color: rgba(59, 113, 210, 1);

			// padding: 20rpx 0;
			image {
				width: 50rpx;
				height: 35rpx;
				padding: 0 20rpx;
			}
		}

		// 导航
		.nav {
			background-color: #FFFFFF;
			display: flex;
			justify-content: space-around;
			align-items: center;

			//padding: 10rpx;
			//margin-bottom: 20rpx;
			.li {
				font-size: 35rpx;
				font-weight: bold;
				font-family: PingFang SC;
				font-weight: 500;
				color: rgba(73, 72, 72, 1);
				text-align: center;
				border-bottom: 2px solid #FFFFFF;

				&.active {
					border-color: rgba(59, 113, 210, 1);
					color: rgba(59, 113, 210, 1);
				}

				padding: 0;
				// margin-top: 20rpx;
				// height: 10rpx;


				// .row {
				// 	width: 100rpx;
				// 	height: 2px;
				// 	background: rgba(59, 113, 210, 1);
				// 	border-radius: 3px;
				// 	margin-top: 20rpx;
				// }
			}


		}

		//T恤
		.Shirt {
			background-color: #FFFFFF;
			display: flex;
			flex-wrap: wrap;
			border-top: 1rpx solid #eeeeee;
			margin-bottom: 200rpx;

			.li {
				//background-image: ;
				width: 50%;
				border-right: 1rpx solid #eeeeee;
				border-bottom: 1rpx solid #eeeeee;

				&:nth-child(2n) {
					border-right: none;
				}

				box-sizing: border-box;
				display: flex;
				justify-content: center;
				flex-wrap: wrap;
				padding-top: 20rpx;

				image {
					width: 80%;
					height: 300rpx;
					margin: auto;
				}

				.text {
					padding: 20rpx 0;
					width: 100%;
					text-align: center;
					font-size: 28rpx;
					font-family: PingFang SC;
					font-weight: 500;
					color: rgba(59, 113, 210, 1);
				}
			}
		}

		.bot {
			display: flex;
			position: fixed;
			bottom: 0rpx;
			justify-content: space-around;
			align-items: center;
			width: 100%;
			background-color: #FFFFFF;
			font-size: 25rpx;
			text-align: center;

			.left {
				padding: 20rpx 0;

				image {
					width: 50rpx;
					height: 50rpx;
				}

				.active {
					color: #0081FF;
				}
			}
		}
	}
</style>
